<!-- This is a test for crbug.com/412440, tests meaningful information in
WebGL context creation error message. -->
<script src="../../resources/js-test.js"></script>
<canvas id="webgl-canvas" width="200" height="200" class="nomargin"></canvas>
<script>
function main()
{
  if (!window.testRunner) {
    testFailed("Requires window.testRunner");
  } else {
    initTest();
  }
}

function initTest() {
  var canvas = document.getElementById("webgl-canvas");
  testRunner.forceNextWebGLContextCreationToFail();
  canvas.addEventListener("webglcontextcreationerror", onContextCreationError, false);
  var gl = canvas.getContext("webgl");
  testRunner.dumpAsText();
}

function onContextCreationError(e) {
  if (e.statusMessage.length == 0) {
    testFailed("webglcontextcreationerror test failed");
    return;
  }
  var splitStatus = e.statusMessage.split(",");
  var error =  "";
  for (var i = 1; i < splitStatus.length; i++) {
    var gpuInfoStr = splitStatus[i].split(" = ");
    var key = gpuInfoStr[0].trim();
    var value = gpuInfoStr[1];
    if (key == "DEVICE" && (value == "0x0000" || value == ""))
      error = error + "DeviceID is null.";
    if (key == "VENDOR" && (value == "0x0000" || value == ""))
      error = error + "VendorID is null.";
  }
  if (error.length)
    testFailed("webglcontextcreationerror test failed " + error);
  else
    testPassed("Status message displayed for webglcontextcreationerror");
}
main();
</script>
